local wen__tiaolv = fk.CreateSkill{
  name = "wen__tiaolv",
}

Fk:loadTranslationTable{
  ["wen__tiaolv"] = "调律",
  [":wen__tiaolv"] = "出牌阶段限一次，你可以弃置一张手牌，然后获得你场上的一张非防具牌。",
  ["#wen__tiaolv-active"] = "调律：弃置一张手牌，然后获得你场上的一张非防具牌",
  ["#wen__tiaolv-select-card"] = "调律：请选择你场上的一张非防具牌",
}

wen__tiaolv:addEffect("active", {
  prompt = "#wen__tiaolv-active",
  max_phase_use_time = 1,
  phase = "play",

  card_num = 1,

  can_use = function(self, player)
    local hasValidCard = false
    for _, cardId in ipairs(player:getCardIds("ej")) do
      local card = Fk:getCardById(cardId)
      if card and card.sub_type ~= Card.SubtypeArmor then
        hasValidCard = true
        break
      end
    end
    return hasValidCard and not player:isKongcheng()
  end,

  card_filter = function(self, player, to_select, selected)
    return #selected == 0
    and table.contains(player:getCardIds("h"), to_select)
    and not player:prohibitDiscard(to_select)
  end,

  on_use = function(self, room, effect)
    local player = effect.from
    room:throwCard(effect.cards, wen__tiaolv.name, player, player)
    if player.dead then return end

    local validCards = {}
    for _, cardId in ipairs(player:getCardIds("ej")) do
      local card = Fk:getCardById(cardId)
      if card and card.sub_type ~= Card.SubtypeArmor then
        table.insert(validCards, cardId)
      end
    end

    if #validCards == 0 then
      room:sendLog{
        type = "#SkillLog",
        from = player.id,
        skill = wen__tiaolv.name,
        content = "无可用的场上非防具牌"
      }
      return
    end

    local chosenCardId = room:askToChooseCard(effect.from, {
      target = effect.from,
      flag = {
        card_data = { { "场上", validCards } }
      },
      prompt = "#wen__tiaolv-select-card",
      skill_name = wen__tiaolv.name
    })

    room:obtainCard(
      effect.from,
      chosenCardId,
      false,
      fk.ReasonPrey,
      effect.from,
      wen__tiaolv.name
    )
  end,
})


return wen__tiaolv